/**
 * home.html page script
 * @author czp
 * date 2018-05-01
 */
var autoHeight = window.innerHeight - 90;
$('.autoHeight').height(autoHeight);
$('#loginGroupCharts').height(autoHeight - 50);
drawLoginGroupCharts();

function drawLoginGroupCharts() {
    var userLoginCharts = echarts.init(document.getElementById("loginGroupCharts"));
    userLoginCharts.showLoading({ text : "数据加载中..." });
    $.ajax({
        url : contextPath + '/manage/loginGroupCount',
        type : 'POST',
        success : function (data) {
            var _legend = [];
            var _data = [];
            data.forEach(function (m) {
                _legend.push(m.c_state);
                _data.push({
                    value : m.num,
                    name : m.c_state
                });
            });
            var option = {
                title : {
                    text: '登陆动作次数统计',
                    x:'center'
                },
                tooltip : {
                    trigger: 'item',
                    formatter: "{b} : {c} 次 ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    top: "5%",
                    left: 'left',
                    data: _legend
                },
                toolbox: {
                    show : true,
                    feature : {
                        mark : {show: true},
                        dataView : {show: true, readOnly: false},
                        restore : {show: true},
                        saveAsImage : {show: true}
                    }
                },
                series : [
                    {
                        name: '登陆动作次数统计',
                        type: 'pie',
                        radius : '60%',
                        center: ['50%', '60%'],
                        data: _data,
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            userLoginCharts.clear();
            userLoginCharts.setOption(option);
            userLoginCharts.hideLoading();
        },
        error : function () {
            userLoginCharts.showLoading({ text : "加载错误..." });
        }
    });
}
